const { getUserId } = require('../../utils')

const notice = {
  async notices (parent, { first, skip, after, isMine }, ctx, info) {
    const userId = getUserId(ctx)
    const where = {}
    if (isMine) {
      where.formUser = {
        id: userId
      }
    } else {
      where.toUser = {
        id: userId
      }
    }
    return ctx.db.query.notices({
      first,
      skip,
      after,
      where
    }, info)
  }
}

module.exports = { notice }
